import clickhouse_connect
import random
from datetime import datetime, timedelta

connect_info = {
    'port': 8123,
    'host': '192.168.103.43',
    'username': 'admin',
    'password': '@Abcd1234',
    'database': 'saas'
}
client = clickhouse_connect.get_client(**connect_info)
column_list = ['log_id', 'log_time', 'login_id', 'person_name', 'tel_number', 'acct_type', 'id_card', 'person_org_name',
               'org_code', 'org_name_path', 'original_log_time']
insert_data = []
num = 0
table_name = 'dr_external_bwd_emp_info_local'
area_codes = [
    '110101', '110102', '110105',  # 北京市
    '310101', '310104', '310105',  # 上海市
    '440103', '440104', '440106',  # 广州市
    '420102', '420103', '420104',  # 武汉市
    '500101', '500102', '500103'  # 重庆市
]
while num < 20008:
    log_id = str(random.randint(10 ** 14, 10 ** 16))
    str_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    log_time = datetime.strptime(str_time, '%Y-%m-%d %H:%M:%S')
    login_id = datetime.now().strftime('%Y%m%d%H%M%S') + str(num).zfill(6)
    person_name = 'test'
    tel_number = '1' + random.choice('3456789') + str(random.randint(0, 999999999)).zfill(9)
    acct_type = '员工账号'
    area_code = random.choice(area_codes)
    start_date = datetime(1900, 1, 1)
    end_date = datetime.now() - timedelta(days=365 * 18)  # 至少18岁
    random_days = random.randint(0, (end_date - start_date).days)
    birth_date = start_date + timedelta(days=random_days)
    birth_code = birth_date.strftime("%Y%m%d")
    seq_code = f"{random.randint(0, 999):03d}"
    str_check_code = '0123456789X'
    check_code = random.choice(str_check_code)
    id_card = area_code + birth_code + seq_code + check_code
    person_org_name = '账务支撑室'
    org_code = '185'
    org_name_path = '上海移动/信息技术管理部/账务支撑室'
    yesterday_time = datetime.now() - timedelta(days=1)
    str_yesterday = yesterday_time.strftime('%Y-%m-%d %H:%M:%S')
    original_log_time = datetime.strptime(str_yesterday, '%Y-%m-%d %H:%M:%S')
    insert_data.append([log_id, log_time, login_id, person_name, tel_number, acct_type, id_card, person_org_name,
                        org_code, org_name_path, original_log_time])
    num += 1
client.insert(table_name, data=insert_data, column_names=column_list)
client.close()
